using System.Data.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;

namespace ABP.TPLMS.EntityFrameworkCore
{
    public static class TPLMSDbContextConfigurer
    {
        public static void Configure(DbContextOptionsBuilder<TPLMSDbContext> builder, string connectionString)
        {
            builder.UseLoggerFactory(MyLoggerFactory).UseSqlServer(connectionString);
            //builder.UseMySql(connectionString);
        }

        public static void Configure(DbContextOptionsBuilder<TPLMSDbContext> builder, DbConnection connection)
        {
            builder.UseLoggerFactory(MyLoggerFactory).UseSqlServer(connection);
            //builder.UseMySql(connection);

        }
        public static readonly LoggerFactory MyLoggerFactory
            = new LoggerFactory(new[]
            {
                new ConsoleLoggerProvider((category, level)
                    => category == DbLoggerCategory.Database.Command.Name
                       && level == LogLevel.Information, true)
            });
    }
}
